package com.health.life;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.support.v4.app.FragmentActivity;
import android.view.WindowManager;
import android.widget.Toast;
import com.health.life.utils.InternetUtil;

/**
 * Created by tukela on 2015/6/8.
 */
public class MyBaseActivity extends FragmentActivity {
    private ProgressDialog progressDialog;
    public boolean isFirst=true;
    public static final String DO_FINISH="DO_FINISH";
    public static final int FINISH_CODE=0x346789;
    public static final int REQUESRCODE=0x2;

    public  void hideFocus() {

        getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                        | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    }
    public boolean isFirst() {
        SharedPreferences shareRefrence=getSharedPreferences("sp",MODE_PRIVATE);
        isFirst=shareRefrence.getBoolean("isfrist",true);
        return isFirst;
    }

    public void setIsFirst(boolean isFirst) {
        SharedPreferences.Editor shareRefrence=getSharedPreferences("sp",MODE_PRIVATE).edit();
        shareRefrence.putBoolean("isfrist",isFirst);
        shareRefrence.apply();
    }

    public void showToaskMsg(String stirng){
        Toast.makeText(this, stirng, Toast.LENGTH_SHORT).show();
    }
    public void showDialogMsg(String title, String msg){
        new AlertDialog.Builder(this)
                .setIcon(R.drawable.ic_launcher)
                .setTitle(title)
                .setMessage(msg)
                .create()
                .show();
    }
    public void showDialogMsg(String msg){
        new AlertDialog.Builder(this)
                .setIcon(R.drawable.ic_launcher)
                .setTitle("提示")
                .setMessage(msg)
                .create()
                .show();
    }
    public void showNetErrorMsg() {
        Toast.makeText(this, "网络异常！", Toast.LENGTH_SHORT).show();
    }

    public boolean isNetMsg(){
        if (InternetUtil.isConnectInternet(this)) {
           return  true;
        }
        Toast.makeText(this, "当前网络不可用", Toast.LENGTH_LONG).show();
        return false;
    }


    /******
     * j加载提示
     */
    public void showPressDialog(){
        if (progressDialog==null)
            progressDialog= new ProgressDialog(this);
        progressDialog.setMessage("加载中，请稍等...");
        progressDialog.setCancelable(true);
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();
    }
    public void showPressDialog(String msg){
        if (progressDialog==null)
            progressDialog= new ProgressDialog(this);
        progressDialog.setMessage(msg);
        progressDialog.setCancelable(true);
        progressDialog.setCanceledOnTouchOutside(false);
        progressDialog.show();
    }

    /*****
     * 取消加载提示
     */
    public void cancelPressDialog(){
        try {
            if (progressDialog!=null)
            progressDialog.cancel();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }






//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        TextView textView=new TextView(this);
//        setContentView(textView);
//        pickDialog(this, new CityDatabase(this).selectProvince(), "PROVINCE",textView);
//    }
}
